package cn.iocoder.yudao.module.system.dal.mysql.erp.customerinformation;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.erp.customerinformation.CustomerInformationDO;
import cn.iocoder.yudao.module.system.controller.admin.erp.customerinformation.vo.CustomerInformationPageReqVO;

/**
 * 客户信息 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface CustomerInformationMapper extends BaseMapperX<CustomerInformationDO> {

    default PageResult<CustomerInformationDO> selectPage(CustomerInformationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CustomerInformationDO>()
                .betweenIfPresent(CustomerInformationDO::getCreateTime, reqVO.getCreateTime())
//                .likeIfPresent(CustomerInformationDO::getNickname, reqVO.getNickname())
                .eqIfPresent(CustomerInformationDO::getDeposit, reqVO.getDeposit())
                .eqIfPresent(CustomerInformationDO::getBalancePayment, reqVO.getBalancePayment())
                .eqIfPresent(CustomerInformationDO::getRemake, reqVO.getRemake())
                .eqIfPresent(CustomerInformationDO::getCustomerId, reqVO.getCustomerId())
                .inIfPresent(CustomerInformationDO::getCustomerId, reqVO.getCustomerIds())
                .apply(" (SELECT COUNT(0)>0 FROM system_users u WHERE u.id=t.customer_id and u.deleted=0 AND u.nickname LIKE '%"+reqVO.getNickname()+"%')")
                .orderByDesc(CustomerInformationDO::getId));
    }

}